﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CheckRes : MonoBehaviour {

        bool testLocalCfg = false;



	// Use this for initialization
	void Start () {

        if ( testLocalCfg )
        {
            DataManager.Init(() => { });
            return;
        }




        Loading.GetInstance ().StartLoading ();

		int count = 0;
        bool netReach = false;
        if (Application.internetReachability != NetworkReachability.NotReachable)
            netReach = true;

        // 检查是否有网络
        //        if (Application.internetReachability != NetworkReachability.NotReachable) {

        Debug.Log("in    net reachable = " + netReach);
			// 有网，下载配置文件
			ResLoader.Load(DataManager.urlGame, null, (www)=>{
				count++;
				if ( count >= 5 )
				{
					
					// data
					DataManager.Init ( ()=>{

                        // next step
                        User.CheckAutoLogin();
                        Loading.GetInstance().EndLoading();

                        /*                        if ( test )
                                                {
                                                    lessonUI.GetInstance().ShowLessonList();
                                                    Loading.GetInstance ().EndLoading ();
                                                    gameObject.transform.parent.gameObject.SetActive (false);
                                                }*/


                    } );
				}
			}, true, false);

			ResLoader.Load(DataManager.urlLesson, null, (www)=>{
				count++;
				if ( count >= 5 )
				{

					// data
					DataManager.Init ( ()=>{

                        // next step
                        User.CheckAutoLogin();
                        Loading.GetInstance().EndLoading();

                        /*                        if ( test )
                                                {
                                                    lessonUI.GetInstance().ShowLessonList();
                                                    Loading.GetInstance ().EndLoading ();
                                                    gameObject.transform.parent.gameObject.SetActive (false);
                                                }*/
                    });
				}
			}, true, false);

			ResLoader.Load(DataManager.urlVideo, null, (www)=>{
				count++;
				if ( count >= 5 )
				{
					// data
					DataManager.Init ( ()=>{

                        // next step
                        User.CheckAutoLogin();
                        Loading.GetInstance().EndLoading();

                        /*                        if ( test )
                                                {
                                                    lessonUI.GetInstance().ShowLessonList();
                                                    Loading.GetInstance ().EndLoading ();
                                                    gameObject.transform.parent.gameObject.SetActive (false);
                                                }*/
                    });
				}
			}, true, false);

            ResLoader.Load(DataManager.urlKejian, null, (www) => {
                count++;
                if (count >= 5)
                {

                    // data
                    DataManager.Init(() => {
                        // next step
                        User.CheckAutoLogin();
                        Loading.GetInstance().EndLoading();
                        /*                        if ( test )
                                                {
                                                    lessonUI.GetInstance().ShowLessonList();
                                                    Loading.GetInstance ().EndLoading ();
                                                    gameObject.transform.parent.gameObject.SetActive (false);
                                                }*/
                    });
                }
            }, true, false);

            ResLoader.Load(DataManager.urlYiguzuoqi, null, (www) => {
                count++;
                if (count >= 5)
                {

                    // data
                    DataManager.Init(() => {

                        // next step
                        User.CheckAutoLogin();
                        Loading.GetInstance().EndLoading();

                        /*                        if ( test )
                                                {
                                                    lessonUI.GetInstance().ShowLessonList();
                                                    Loading.GetInstance ().EndLoading ();
                                                    gameObject.transform.parent.gameObject.SetActive (false);
                                                }*/
                    });
                }
            }, true, false);

//        }


	}

}
